#include <iostream>
#include <vector>
#include <memory>
#include <string>

using namespace std;

class Drone
{
public:
    Drone(int x_, string url_) : x{x_}, url{url_}
    {
        printf("x_=%d\n", x_);
    }
    int x;
    string url;
};

class Group
{
public:
    Group()
    {
        followers.reserve(10);
    }
    void add_drone(int id)
    {
        string url = "drone" + to_string(id);
        // 1) 创建临时变量并放入vector
        // auto new_drone = make_shared<Drone>(id, url);
        // printf("add_drone: %d, %s\n", new_drone->x, new_drone->url.c_str());
        // followers.push_back(new_drone);

        // 2)
        followers.emplace_back(make_shared<Drone>(id, url));
    }
    void print()
    {
        for (int i = 0; i < followers.size(); ++i)
        {
            printf("drone: id=%d, url=%s\n", followers[i]->x, followers[i]->url.c_str());
        }
    }
    vector<shared_ptr<Drone>> followers;
};

void test01()
{
    Group group;
    group.add_drone(1);
    group.add_drone(2);
    group.print();
}
int main(int argc, char argv)
{
    test01();
    return 0;
}